# -*- coding: utf-8 -*-

import os
import datetime

server_ip = os.popen('ifconfig eth0|grep inet|grep -v 127.0.0.1|grep -v inet6|awk \'{print $2}\'|tr -d "addr:"').readlines()[0].strip('\r\n')
server_port = 15511
bind = '%s:%s' % (server_ip, server_port)

backlog = 2048 # the maximum number of pending connections
workers = 1# the number of worker processes for handling requests(2-4 workers per core)
worker_class = 'gevent'
worker_connections = 2048 # the maximum number of simultaneous clients

loglevel = 'info'
script_path = os.path.dirname(os.path.abspath(__file__))
work_path = os.path.dirname(script_path)
pidfile = '{}/gunicorn.pid'.format(script_path)
errorlog = '{}/log/gunicorn_error.log'.format(work_path)
chdir = '{}/src'.format(work_path)


def worker_exit(server, worker):
    pid = worker.pid
    logfile = os.path.join(work_path, 'log/xyf_customtag.{}.log'.format(pid))
    newfile = os.path.join(work_path, 'log/xyf_customtag.{}.log.{}'.format(
        pid, datetime.datetime.now().strftime('%Y-%m-%d')))
    if os.path.exists(logfile):
        os.rename(logfile, newfile)
